﻿using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using log4net;
using Microsoft.ApplicationBlocks.Data;
using FunkeLab;
using System.Reflection;
using AnyOffice.general.ipanel;

namespace AnyOffice.general.ipanel
{
    public partial class user_all : BasePage
    {
        protected MyTreeViewItem nodeParent;
        protected MyTreeViewItem nodeUser;

        private static ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

     
        private void LoadNode(ref MyTreeViewItem nodeParent, int DeptId)
        {
            DataTable table = new DepartmentDao().SelectChildAll(base.Conn, DeptId);
            UsersDao dao2 = new UsersDao();
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    MyTreeViewItem item = new MyTreeViewItem();
                    item.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                    item.Image = "/images/node_dept.gif";
                    DataTable table2 = dao2.SelectBaseByDeptId(base.Conn, Convert.ToInt32(table.Rows[i]["DeptId"].ToString()));
                    if (table2.Rows.Count > 0)
                    {
                        for (int j = 0; j < table2.Rows.Count; j++)
                        {
                            this.nodeUser = new MyTreeViewItem();
                            this.nodeUser.Text = (table2.Rows[j]["UserName"] == DBNull.Value) ? "" : table2.Rows[j]["UserName"].ToString();
                            this.nodeUser.Image = "/images/node_user.gif";
                            this.nodeUser.Link = "user_info.aspx?user_id=" + table2.Rows[j]["UserId"].ToString();
                            this.nodeUser.TargetFrame = "main";
                            item.Items.Add(this.nodeUser);
                        }
                    }
                    this.LoadNode(ref item, int.Parse(table.Rows[i]["DeptId"].ToString()));
                    nodeParent.Items.Add(item);
                }
            }
        }
 

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!this.Page.IsPostBack)
                {
                    DataTable table = new DepartmentDao().SelectParentAll(base.Conn);
                    UsersDao dao2 = new UsersDao();
                    if (table.Rows.Count > 0)
                    {
                        for (int i = 0; i < table.Rows.Count; i++)
                        {
                            this.nodeParent = new MyTreeViewItem();
                            this.nodeParent.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                            this.nodeParent.Image = "/images/node_dept.gif";
                            DataTable table2 = dao2.SelectBaseByDeptId(base.Conn, Convert.ToInt32(table.Rows[i]["DeptId"].ToString()));
                            if (table2.Rows.Count > 0)
                            {
                                for (int j = 0; j < table2.Rows.Count; j++)
                                {
                                    this.nodeUser = new MyTreeViewItem();
                                    this.nodeUser.Text = (table2.Rows[j]["UserName"] == DBNull.Value) ? "" : table2.Rows[j]["UserName"].ToString();
                                    this.nodeUser.Image = "/images/node_user.gif";
                                    this.nodeUser.Link = "user_info.aspx?user_id=" + table2.Rows[j]["UserId"].ToString();
                                    this.nodeUser.TargetFrame = "main";
                                    this.nodeParent.Items.Add(this.nodeUser);
                                }
                            }
                            this.LoadNode(ref this.nodeParent, int.Parse(table.Rows[i]["DeptId"].ToString()));
                            this.TreeView1.Items.Add(this.nodeParent);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("", exception);
                }
            }
        }

 

 

    }
}
